package cn.tj.controller;

import cn.tj.entity.PageBean;
import cn.tj.entity.Result;
import cn.tj.entity.Technician;
import cn.tj.service.TechnicianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/technician")
public class TechnicianController {
    @Autowired
    private TechnicianService technicianService;

    /**
     * 条件分页查询技师列表
     * @param currentPage
     * @param pageSize
     * @param typeId 类型id
     * @param name 名字
     * @return
     */
    @GetMapping("/listByPage")
    public Result listByPage(
            Integer currentPage,
            Integer pageSize,
            @RequestParam(required = false) Integer typeId,
            @RequestParam(required = false) String name

    ){
        PageBean pg = technicianService.listByPage(currentPage,pageSize,typeId,name);
        return Result.success(pg);
    }

    /**
     * 通过id获取技师信息
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public Result<Technician> getById(Integer id){
        Technician t=technicianService.getById(id);
        return Result.success(t);
    }

    /**
     * 根据id修改信息
     * @param technician
     * @return
     */
    @PutMapping("/edit")
    public Result editById(@RequestBody Technician technician){
        technicianService.editById(technician);
        return Result.success();
    }

    /**
     * 新增信息
     * @param technician
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Technician technician){
        technicianService.add(technician);
        return Result.success();
    }

    /**
     * 根据id删除信息
     * @param id
     * @return
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id){
        technicianService.deleteById(id);
        return Result.success();
    }
}
